package com.itheima.controller;

import com.itheima.domain.User;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping ("/user")
public class UserController {
        // 普通参数
        @RequestMapping("/commonParam")
        @ResponseBody
        public String commonParam(String name, int age) {
            System.out.println("普通参数传递 name ==> " + name);
            System.out.println("普通参数传递 age ==> " + age);
            return "{'module':'common param'}";
        }

        // 普通参数：请求参数名与形参名不同
        @RequestMapping("/commonParamDifferentName")
        @ResponseBody
        public String commonParamDifferentName( @RequestParam("name") String userName, int age) {
            System.out.println("普通参数传递 userName ==> " + userName);
            System.out.println("普通参数传递 age ==> " + age);
            return "{'module':'common param different name'}";
        }

        // POJO参数
        @RequestMapping("/pojoParam")
        @ResponseBody
        public String pojoParam( User user) {
            System.out.println("pojo参数传递 user ==> " + user);
            return "{'module':'pojo param'}";
        }

        @RequestMapping("/pojoContainPojoParam")
        @ResponseBody
        public String pojoContainPojoParam(User user) {
             System.out.println("pojo嵌套pojo参数传递 user ==> " + user);
             return "{'module':'pojo param'}";
        }

        @RequestMapping("/arrayParam")
        @ResponseBody
        public String arrayParam(String[] likes) {
             System.out.println("数组参数传递 likes ==> " + Arrays.toString(likes));
             return "{'module':'array param'}";
        }

        @RequestMapping("/listParam")
        @ResponseBody
        public String listParam(@RequestParam List<String> likes) {
             System.out.println("数组参数传递 likes ==> " + likes);
             return "{'module':'list param'}";
    }

}


